home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / xpkmaster / fib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-02  |  2.1 KB  |  92 lines

  1. #ifndef XPKMASTER_FIB_C
  2. #define XPKMASTER_FIB_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        fib.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: fib.c 1.0 (05.10.96)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    FIB related routines
  12.  
  13.  1.0   05.10.96 : first real version
  14. */
  15.  
  16. #include <pragma/exec_lib.h>
  17. #include <pragma/dos_lib.h>
  18. #include <exec/types.h>
  19. #include "xpkmaster.h"
  20.  
  21. void updatefib(struct XpkBuffer *xbuf)
  22. {
  23.   struct XpkStreamHeader *globhdr = &xbuf->xb_Headers.h_Glob;
  24.   XpkChunkHeader *lochdr = &xbuf->xb_Headers.h_Loc;
  25.   struct XpkFib *fib = &xbuf->xb_Fib;
  26.   LONG ulen, clen;
  27.  
  28.   if(xbuf->xb_Headers.h_Glob.xsh_Flags & XPKSTREAMF_LONGHEADERS)
  29.   {
  30.     ulen = lochdr->xch_Long.xchl_ULen;
  31.     clen = lochdr->xch_Long.xchl_CLen;
  32.   }
  33.   else
  34.   {
  35.     ulen = lochdr->xch_Word.xchw_ULen;
  36.     clen = lochdr->xch_Word.xchw_CLen;
  37.   }
  38.  
  39.   fib->xf_Type = XPKTYPE_PACKED;
  40.   fib->xf_CLen = globhdr->xsh_CLen + 8;
  41.   fib->xf_ULen = globhdr->xsh_ULen;
  42.   fib->xf_NLen = ulen + XPK_MARGIN;
  43.   fib->xf_CCur += ROUNDLONG (clen) + xbuf->xb_Headers.h_LocSize;
  44.   fib->xf_UCur += ulen;
  45.   fib->xf_ID = globhdr->xsh_Type;
  46.   fib->xf_SubVersion = globhdr->xsh_SubVrs;
  47.   fib->xf_MasVersion = globhdr->xsh_MasVrs;
  48.   CopyMem(globhdr->xsh_Initial, fib->xf_Head, 16);
  49.  
  50.   percentages(fib);
  51. }
  52.  
  53. /*
  54. void storefib (struct XpkBuffer *xbuf)
  55. {
  56.   struct Headers globloc;
  57.   UBYTE comment[80];
  58.   STRPTR in = (STRPTR) &globloc, out = comment;
  59.  
  60.   if (!xbuf->xb_OutName || !(xbuf->xb_Flags & XMF_USECOMMENT))
  61.     return;
  62.  
  63.   CopyMem(&xbuf->xb_Headers, &globloc, sizeof(struct Headers));
  64.   globloc.h_LocSize = 0;
  65.  
  66.   *(out++) = 'X'; *(out++) = 'P'; *(out++) = 'K'; *(out++) = 'F';
  67.  
  68.   for(; in < (STRPTR) &globloc + sizeof(struct Headers) - 4; in += 3)
  69.   {
  70.     *out++ = 64 | (in[0] & 3) << 4 | (in[1] & 3) << 2 | in[0] & 3;
  71.     *out++ = 64 | in[0] >> 2;
  72.     *out++ = 64 | in[1] >> 2;
  73.     *out++ = 64 | in[2] >> 2;
  74.   }
  75.   *out = 0;
  76.  
  77.   SetComment(xbuf->xb_OutName, comment);
  78. }
  79. */
  80. void percentages (struct XpkFib *fib)
  81. {
  82.   fib->xf_Ratio = 0;
  83.   if(fib->xf_ULen)
  84.     fib->xf_Ratio = 100 - 100 * fib->xf_CLen / fib->xf_ULen;
  85.   if(fib->xf_Ratio < 0)
  86.     fib->xf_Ratio = 0;
  87.   *(LONG *) fib->xf_Packer = fib->xf_ID;
  88.   fib->xf_Packer[4] = 0;
  89. }
  90.  
  91. #endif /* XPKMASTER_FIB_C */
  92.